package com.suitsoft.bdms.web.system;

import java.util.List;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.suitsoft.bdms.commos.LogAnnotation;
import com.suitsoft.bdms.entity.system.SystemCategory;
import com.suitsoft.bdms.service.system.SystemCategoryManager;
import com.suitsoft.bdms.web.CrudActionSupport;

/**
 * 系统参数类别
 *@author Suineg
 */
@Results({@Result(name=CrudActionSupport.RELOAD,location="system-category.action",type="redirect")})
public class SystemCategoryAction extends CrudActionSupport<SystemCategory>{
	/**
	 * 
	 */
	private static final long serialVersionUID = 9042673842056780905L;
	/** 日志输出对象 */
	protected final Logger logger = LoggerFactory.getLogger(getClass());
	
	private SystemCategoryManager systemCategoryManager;
	
	private SystemCategory category;
	private Long id;
	private List<SystemCategory> categoryList;

	@Override
	@LogAnnotation(log = "系统参数类别管理  - 删除")
	public String delete() throws Exception {
		if(id == null || id == 0l){
			addActionMessage("非法操作！");
			return list();
		}
		systemCategoryManager.delete(id);
		addActionMessage("删除成功！");
		return RELOAD;
	}

	@Override
	public String input() throws Exception {
		return INPUT;
	}

	@Override
	public String list() throws Exception {
		categoryList = systemCategoryManager.getAll();
		return SUCCESS;
	}

	@Override
	protected void prepareModel() throws Exception {
		if(id != null){
			category = systemCategoryManager.get(id);
		}else{
			category = new SystemCategory();
		}
		
	}

	@Override
	@LogAnnotation(log = "系统参数类别管理 - 保存")
	public String save() throws Exception {
		systemCategoryManager.save(category);
		addActionMessage("保存成功");
		return RELOAD;
	}

	@Override
	public SystemCategory getModel() {
		return category;
	}
	@Autowired
	public void setSystemCategoryManager(SystemCategoryManager systemCategoryManager) {
		this.systemCategoryManager = systemCategoryManager;
	}

	public SystemCategory getCategory() {
		return category;
	}

	public void setCategory(SystemCategory category) {
		this.category = category;
	}
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public List<SystemCategory> getCategoryList() {
		return categoryList;
	}
	public void setCategoryList(List<SystemCategory> categoryList) {
		this.categoryList = categoryList;
	}
}

